//获取数据库的内容渲染到页面
// const tbody = $('#tbody-shop')
getData()

function getData() {
   $.ajax({
      url: './api/shop/select.php',
      method: 'get',
      success: resp => {
         console.log(resp)
         const {
            list
         } = resp.body
         let str = ''
         list.forEach((item, index) => {
            str += `
               <tr data-id=${item.id}> 
                  <td>${index+1}</td>
                  <td><span>${item.name}</span><input type="text" class='name'></td>
                  <td><span> ${item.price}</span><input type="text" class='price'></td>
                  <td><span>${item.num}</span><input type="text" class='num'></td>
                  <td>
                     <button class="btn btn-info btn-xs btn-edit">编辑</button>
                     <button class="btn btn-danger btn-xs btn-del">删除</button>
                     <button class="btn btn-success btn-xs btn-ok">确定</button>
                     <button class="btn btn btn-warning btn-xs btn-cancel">取消</button>
                  </td>
            </tr>
           `
         })
         $('#tbody-shop').html(str)
      },
      error: () => {
         console.log('失败')
      },
      dataType: 'json'
   })
}